// 枚举类型
#[derive(Debug)]
enum IpAddrKind {
    V4,
    V6,
}

// ip地址
#[derive(Debug)]
enum IpAddr {
    V4(String),
    V6(String),
}

#[derive(Debug, Clone)]
struct User {
    user_id: u64,
    name: String,
}

#[derive(Debug)]
enum ChatroomMessage {
    Enter(User),
    SendMessage(User, String),
    Notice(String),
    Exit(User),
}



fn main() {
    let five = plus_one(Some(4));
    let six = plus_one(five);
    let none = plus_one(None);

    println!("{:?} {:?} {:?}", five, six, none)
}

fn plus_one(x: Option<i32>) -> Option<i32> {
    match x {
        None => None,
        Some(i) => Some(i + 1),
    }
}


fn main_chatroom_msg() {
    let u = User {
        user_id: 1,
        name: String::from("Li Lei"),
    };
    let msg_list = [
        ChatroomMessage::Enter(u.clone()),
        ChatroomMessage::Notice("Welcome!".to_owned()),
        ChatroomMessage::SendMessage(u.clone(), "hello every one".to_owned()),
        ChatroomMessage::Exit(u.clone()),
    ];
    for msg in msg_list {
        match msg {
            ChatroomMessage::Enter(user) => println!("{} is enter this chatroom", user.name),
            ChatroomMessage::SendMessage(user, s) => println!("{}: {}", user.name, s),
            ChatroomMessage::Notice(s) => println!("Hey,guys!{}", s),
            ChatroomMessage::Exit(user) => println!("{} exit this chatroom", user.name),
        }
    }
}